package com.zjl.springmvc.controller.xxxBody;

import org.springframework.http.RequestEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController//
public class requestBodyController {

    /**
     * 在html  的 from 表单中  添加
     *  enctype="text/plain"   解决中文乱码
     *
     */
    @RequestMapping ("/requestBody")
    public Map requestBody(
            //获取请求体（是 post 请求）数据  会乱码
            @RequestBody(required = false) String content,
            //获得指定请求头
            @RequestHeader(value = "User-Agent",required = false) String userAgent,
            //获取所有请求头
            @RequestHeader Map<String,String> header
    ){
        Map<String,Object> map=new HashMap<>();
        map.put("content",content);
        return map;
    }//详见 body.html
    @RequestMapping("/requestEntity")
    public Map requestEntity(
            //获取整个请求报文信息
            RequestEntity<String> content){
        Map<String,Object> map=new HashMap<>();
        map.put("请求头",content.getHeaders());
        map.put("请求体",content.getBody());
        return map;
    }//详见 body.html

}
